﻿                                                                                                   

         
	using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Linq.Dynamic;
    using System.Text;
    using System.Threading.Tasks;
    using Abp;
    using Abp.Application.Services.Dto;
    using Abp.Authorization;
    using Abp.AutoMapper;
    using Abp.Configuration;
    using Abp.Domain.Repositories;
    using Abp.Extensions;
    using Abp.Linq.Extensions;
    using KDS.Mes.Mes.TestImss.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.TestImss
{
    /// <summary>
    /// IMS检测数据表的导出EXCEL功能的实现
    /// </summary>
    public class TestImsListExcelExporter : EpPlusExcelExporterBase, ITestImsListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public TestImsListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出IMS检测数据表到EXCEL文件
        /// <param name="testImsListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportTestImsToFile(List<TestImsListDto> testImsListDtos){


var file=CreateExcelPackage("testImsList.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("TestIms"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("LINE"),  
     L("STATION_NO"),  
     L("SEAT_ID"),  
     L("RESULT"),  
     L("MEMORY1"),  
     L("MEMORY2"),  
     L("EASY_ACCESS"),  
     L("LIMIT_SLIDE"),  
     L("LIMIT_RECL"),  
     L("LIMIT_FRONT"),  
     L("LIMIT_REAR"),  
     L("CREAT_TIME")  
                        );
         AddObjects(sheet,2,testImsListDtos,
            
      _ => _.LINE,   
       
      _ => _.STATION_NO,   
       
      _ => _.SEAT_ID,   
       
      _ => _.RESULT,   
       
      _ => _.MEMORY1,   
       
      _ => _.MEMORY2,   
       
      _ => _.EASY_ACCESS,   
       
      _ => _.LIMIT_SLIDE,   
       
      _ => _.LIMIT_RECL,   
       
      _ => _.LIMIT_FRONT,   
       
      _ => _.LIMIT_REAR,   
       
 _ =>_timeZoneConverter.Convert( _.CREAT_TIME,_abpSession.TenantId, _abpSession.GetUserId()) 
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 12; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
